home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / examples / r < prev    next >
Encoding:
Text File  |  1994-02-08  |  2.3 KB  |  87 lines

  1. #!/usr/local/bin/icmake -qi
  2.  
  3. /* 
  4.     This simple icmake script starts a given command in the current
  5.     directory, and then recursively in all subdirectories. For the
  6.     installation: see the sample script "tolower" (or, "tolower.im").
  7. */
  8.  
  9. #define VER "1.02"
  10.  
  11. string makecmd (list cmd)            // make one long cmd by
  12. {                        // expanding list elements
  13.     string
  14.         ret;                    // returned cmd
  15.     int
  16.         i,                    // outer/inner loop
  17.         j;                    // counters
  18.     list
  19.         aux;                    // expanded inner list
  20.         
  21.     ret = element (0, cmd);            // add program name itself
  22.     
  23.     for (i = 1; i < sizeof (cmd); i++)        // for all other elements:
  24.     {
  25.         if (aux = makelist (element (i, cmd)))    // expand element, and
  26.             for (j = 0; j < sizeof (aux); j++)    // add expansion
  27.                 ret += " " + element (j, aux);
  28.         else
  29.             ret += " " + element (i, cmd);    // or add unexpanded
  30.     }
  31.     
  32.     return (ret);                // return the string
  33. }
  34.  
  35. void process (list cmd)
  36. {
  37.     list
  38.         dirs;                    // list of subdirs
  39.     int
  40.         i;                    // counter for subdirs or
  41.     string                    // command name list
  42.         cwd,                    // stored current working dir
  43.         sys;                    // expanded command to run
  44.                             
  45.     cwd = chdir (".");                // get cwd
  46.     printf ("==== r: directory ", cwd,         // print this dir
  47.         " ====\n");
  48.     
  49.     sys = makecmd (cmd);            // make and the command
  50.     system (P_NOCHECK, sys);            // run the command
  51.     
  52.     if (dirs = makelist (O_SUBDIR, "*"))    // get list of subdirs
  53.     {
  54.     for (i = 0; i < sizeof (dirs); i++)    // for each one:
  55.     {
  56.         chdir (element (i, dirs));        // go there
  57.         process (cmd);            // recursively run cmd
  58.         chdir (cwd);            // and.. back again
  59.     }    
  60.     }    
  61. }
  62.  
  63. void main (int argc, list argv)
  64. {
  65.     echo (0);                    // suppress re-echoing
  66.  
  67.     if (argc == 1)                // usage info if no
  68.     {                        // cmdline arguments
  69.         printf ("ICCE Recursive Command-expander  Version ", VER, "\n"
  70.             "Copyright (c) ICCE 1993. All rights reserved.\n"
  71.             "\n"
  72.             "Usage: r program arguments\n"
  73.             "Will run \"program arguments\" in this directory and"
  74.                         " recursively in the\n"
  75.             "subdirectories.\n"
  76.             "\n");
  77.         exit (1);
  78.     }
  79.     
  80.     argv -= (list) element (0, argv);        // remove makefile name
  81.     
  82.     process (argv);                // and.. start at current
  83.                             // dir
  84.                             
  85.     exit (0);                    // done.
  86. }
  87.